<template>
	<a-modal :visible="visible" :title="title" @Ok="fun_submit" @cancel="fun_cancel">
		<a-form name="tt" v-model="formData" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
			<template v-for="item in columns" :key="item.dataIndex">
				<a-form-item v-if="item.edit" :label="item.title" :name="item.dataIndex">
					<a-date-picker v-if="(item.type == 'date')" v-model:value="formData[item.dataIndex]" placeholder="选择日期" />
					<a-date-picker v-else-if="(item.type == 'datetime')" show-time v-model:value="formData[item.dataIndex]" placeholder="选择时间" />
					<a-time-picker v-else-if="(item.type == 'time')" v-model:value="formData[item.dataIndex]" placeholder="选择时间" />

					<a-textarea v-else-if="(item.type == 'text')" v-model:value="formData[item.dataIndex]" />
					<a-radio-group v-else-if="(item.type == 'radio')" v-model:value="formData[item.dataIndex]" :options="item.dict" />
					<a-checkbox-group v-else-if="(item.type == 'checkbox')" v-model:value="formData[item.dataIndex]" name="checkboxgroup" :options="item.dict" />
					<a-select v-else-if="(item.type == 'select')" v-model:value="formData[item.dataIndex]" :options="item.dict"></a-select>

					<a-input-number v-else-if="(item.type == 'int' || item.type == 'long' || item.type == 'decimal')" v-model:value="formData[item.dataIndex]" />
					<a-input v-else v-model:value="formData[item.dataIndex]" />	
					
				</a-form-item>
			</template>
		</a-form>
	</a-modal>
</template>

<script>
	 



export default {
	name: 'tableAdd',
	props: ['columns', 'visible', 'addUrl'],
	data() {
		return {
			title: '添加',
			formData: {},
			local_columns: this.columns,
		};
	},
	methods: {
		/**
		 * @function 提交数据
		 */
		fun_submit() {
			var that = this;
			this.$http.post(this.addUrl, this.formData, this, function (ret) {
				that.$Message['success']({ background: true, duration: 10, content: '添加成功' });
				that.$parent.fatherRefresh(false, true, 'add');
			});
			for (var item in that.formData) {
				that.formData[item] = null;
			} 
		},
		/**
		 * 取消关闭窗口
		 */
		fun_cancel() {
			this.$parent.fatherRefresh(false, false, 'add');
		},
	},
	mounted() {},
};
</script>

<style></style>
